/*==================================================
Project:       Targeting Social Programs
Authors:       Diether W. Beuermann
            Bridget Hoffmann        
            Marco Stampini 
            David L. Vargas
            Diego Vera-Cossio
----------------------------------------------------
Creation Date:    May 2023
Modification Date:   
Do-file version:    01
References:          
Output:             
==================================================*/


/*==================================================
            0: Program set up
==================================================*/
*Written on STATA 17
drop _all
set varabbrev off	// no variable abbreviations allowed (personal preference)

** source dir
cd "${dir5r}" // graph dir


/*==================================================
        1: load and plot
==================================================*/

// Load data from F4 models
use "${dir3r}/03_auxiliar/Boostrap_estimates.dta" , clear

*** Sensitivity to different modeling choices
#delimit ;
tw (connected exclusion_err year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap exclusion_err_uci exclusion_err_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected exclusion_err year if model_n ==  4 & type_m ==  "OLS", 
        mcolor(gray%80) lcolor(gray%80) msym(D) ) 
            (rcap exclusion_err_uci exclusion_err_lci year if model_n ==  4 & type_m ==  "OLS", 
        lcolor(gray%80) ) 	
    (connected exclusion_err year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap exclusion_err_uci exclusion_err_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected exclusion_err year if model_n ==7 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap exclusion_err_uci exclusion_err_lci year if model_n ==7 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic - Common coefficient" 					
                5 "Dynamic - Gain/losses" 
                7 "Dynamic - Gain/losses & formal/informal"	
                ) pos(6) row(2))
    ytitle("Exclusion Error")
    xtitle("Year")
    xlabel(2019(1)2021)
    ylabel(30(5)50)
    name(A, replace)
;
#delimit cr
graph export "FA2_a_model_coefs.png", as(png) replace width(1200)
graph export "FA2_a_model_coefs.pdf", as(pdf) replace 

    #delimit ;
    tw (connected inclusion_err year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap inclusion_err_uci inclusion_err_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected inclusion_err year if model_n ==  4 & type_m ==  "OLS", 
        mcolor(gray%80) lcolor(gray%80) msym(D) ) 
            (rcap inclusion_err_uci inclusion_err_lci year if model_n ==  4 & type_m ==  "OLS", 
        lcolor(gray%80) ) 	
    (connected inclusion_err year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap inclusion_err_uci inclusion_err_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected inclusion_err year if model_n ==7 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap inclusion_err_uci inclusion_err_lci year if model_n ==7 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic - Common coefficient" 					
                5 "Dynamic - Gain/losses" 
                7 "Dynamic - Gain/losses & formal/informal"	
                ) pos(6) row(2))
    ytitle("Inclusion Error")
    xtitle("Year")
    xlabel(2019(1)2021)
    ylabel(15(5)35)
    name(B, replace)
;
#delimit cr
graph export "FA2_b_model_coefs.png", as(png) replace width(1200)
graph export "FA2_b_model_coefs.pdf", as(pdf) replace 


    #delimit ;
    tw (connected crra year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap crra_uci crra_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected crra year if model_n ==  4 & type_m ==  "OLS", 
        mcolor(gray%80) lcolor(gray%80) msym(D) ) 
            (rcap crra_uci crra_lci year if model_n ==  4 & type_m ==  "OLS", 
        lcolor(gray%80) ) 	
    (connected crra year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap crra_uci crra_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected crra year if model_n ==7 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap crra_uci crra_lci year if model_n ==7 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic - Common coefficient" 					
                5 "Dynamic - Gain/losses" 
                7 "Dynamic - Gain/losses & formal/informal"	
                ) pos(6) row(2))
    ytitle("Social Welfare (CRRA: {&rho} = 3)")
    xtitle("Year")
    xlabel(2019(1)2021)
    name(C, replace)
;
#delimit cr
graph export "FA2_c_model_coefs.png", as(png) replace width(1200)
graph export "FA2_c_model_coefs.pdf", as(pdf) replace 

    #delimit ;
    tw (connected hh_benefits year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap hh_benefits_uci hh_benefits_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected hh_benefits year if model_n ==  4 & type_m ==  "OLS", 
        mcolor(gray%80) lcolor(gray%80) msym(D) ) 
            (rcap hh_benefits_uci hh_benefits_lci year if model_n ==  4 & type_m ==  "OLS", 
        lcolor(gray%80) ) 	
    (connected hh_benefits year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap hh_benefits_uci hh_benefits_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected hh_benefits year if model_n ==7 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap hh_benefits_uci hh_benefits_lci year if model_n ==7 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic - Common coefficient" 					
                5 "Dynamic - Gain/losses" 
                7 "Dynamic - Gain/losses & formal/informal"	
                ) pos(6) row(2))

    ytitle("Per-household Transfer ($ USD PPP)")
    xtitle("Year")
    xlabel(2019(1)2021)
    name(D, replace)
;
#delimit cr
graph export "FA2_d_model_coefs.png", as(png) replace width(1200)
graph export "FA2_d_model_coefs.pdf", as(pdf) replace 

